package com.tang.hawkmusic.activity.login;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import com.google.gson.Gson;
import com.tang.hawkmusic.R;
import com.tang.hawkmusic.utill.ThemeUtill;

public class LoginActivity extends AppCompatActivity {
    private LoginViewModel loginViewModel;
    private EditText userName;
    private EditText password;
    private Button loginBtn;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        setStatusBar();
        loginViewModel=new ViewModelProvider(this).get(LoginViewModel.class);
        loginViewModel.setLoginActivity(this);
        initView();
    }

    private void initView(){
        userName =findViewById(R.id.username_login);
        password=findViewById(R.id.password_login);
        loginBtn=findViewById(R.id.loginBtn_login);
        Toast toast=Toast.makeText(this,"登录错误",Toast.LENGTH_SHORT);
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name=userName.getText().toString().trim();
                String pass=password.getText().toString().trim();
               
                if (name.length()>=11&&pass.length()>6){
                    loginViewModel.loginPhone(name,pass);
                }
                else {
                   toast.show();
                }
            }
        });
    }
    //设置状态栏
    public void setStatusBar() {
        ThemeUtill.setAllowDrawUnderStatusBar(getWindow());
    }
    public void showToast(String message){
        Toast toast=Toast.makeText(this,message,Toast.LENGTH_SHORT);
        toast.show();
    }

}

